package cate.game.fight.hero.dyn;

import cate.common.table.dynins.DynHeroLevelRow;
import cate.common.table.dynins.DynHeroRow;
import cate.common.table.item.fairy.row.FairyBaseRow;
import cate.common.table.item.hero.row.HeroBaseRow;
import cate.game.attr.FightAttr;
import cate.game.role.bag.hero.Hero;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

@Slf4j
public class DynFairyUtil extends DynItemUtil {

	@Override
	public void setUp(Hero hero, HeroBaseRow heroTpl, DynHeroLevelRow itemTpl) {
		if (itemTpl.fairyCode < 0) {
			return;
		}
		DynHeroRow dynHeroRow = ctx.dynInsExcel().hero.get(heroTpl.protoId);
		if (dynHeroRow == null) {
			return;
		}
		if (dynHeroRow.fairyProtoId <= 0) {
			return;
		}
		int fairyId = dynHeroRow.fairyProtoId + itemTpl.fairyCode;
		FairyBaseRow fairyRow = ctx.fairyExcel().base.get(fairyId);
		if (fairyRow == null) {
			return;
		}
		hero.exPart.addSkills(new ArrayList<>(fairyRow.skills));
		hero.exPart.addAttr(new FightAttr(fairyRow.attrStr));
	}
}
